package org.hyf.inspur.LessonDesin.clear.count4;


import org.hyf.inspur.LessonDesin.clear.tools.TProperties;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.input.FileSplit;

import java.io.IOException;

public class ProMapper extends Mapper<LongWritable, Text, Text, Text> {
    private Text okey = new Text();
    private Text ovalue = new Text();

    public void map(LongWritable key,Text value,Context context) throws IOException,InterruptedException {
        // hdfs系统
        FileSplit fileSplit = (FileSplit) context.getInputSplit();
        // 全路径
        String path = fileSplit.getPath().toString();
        String[] values = value.toString().split(TProperties.getValue("fileoutsplit"), -1);
        StringBuffer sb = new StringBuffer();
        // 文件名称判断数据类型：配置数据产品库，行为匹配数据
        if (path.indexOf(TProperties.getValue("proaddress")) >= 0){
            okey = new Text(values[0] + ",1");
            // 数据标识 区分数据
            sb.append("1#" + values[1]).append(TProperties.getValue("outfilesplit")).append(values[2])
                    .append(TProperties.getValue("outfilesplit")).append(values[3])
                    .append(TProperties.getValue("outfilesplit")).append(values[4])
                    .append(TProperties.getValue("outfilesplit")).append(values[5])
                    .append(TProperties.getValue("outfilesplit")).append(values[6])
                    .append(TProperties.getValue("outfilesplit")).append(values[7])
                    .append(TProperties.getValue("outfilesplit")).append(values[8]);
            ovalue = new Text(sb.toString());
            context.write(okey, ovalue);
        } else {
            // 处理任务2的输出数据：行为匹配数据 拿取产品类型数据
            if("1".equals(values[2])) {
                //行为id+数据类型标识
                okey = new Text(values[0] + ",2");
                //用户id
                sb.append(values[1]);
                ovalue = new Text(sb.toString());
                context.write(okey, ovalue);
                // 行为id,2,用户id
            }
        }
        //System.out.println("1111111111111111111111");
    }
}
